/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.tarena.lbs.attach.rpc;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tarena.lbs.attach.api.AttachApi;
import com.tarena.lbs.attach.dao.mapper.AttachMapper;
import com.tarena.lbs.attach.pojo.dto.AttachDTO;
import com.tarena.lbs.attach.pojo.dto.AttachQrDTO;
import com.tarena.lbs.attach.pojo.param.AttachQRParam;
import com.tarena.lbs.attach.pojo.param.PicUpdateParam;
import com.tarena.lbs.attach.pojo.po.AttachPO;
import com.tarena.lbs.attach.pojo.query.AttachQuery;
import com.tarena.lbs.attach.service.AttachService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;

@DubboService
@Slf4j
public  class AttachRpcService  implements AttachApi {

    @Autowired
    private AttachService attachService;

    @Override
    public List<AttachDTO> getAttachInfo(AttachQuery attachQuery) {
        return Collections.emptyList();
    }

    @Override
    public boolean batchUpdateBusiness(List<PicUpdateParam> picParams) {
        log.info("开始批量更新业务信息，参数数量: {}", picParams != null ? picParams.size() : 0);

        try {
            // 参数校验
            if (picParams == null || picParams.isEmpty()) {
                log.warn("批量插入业务信息的参数为空");
                return true;
            }

            // 验证必要参数
            for (PicUpdateParam param : picParams) {
                if (param.getFileUuid() == null || param.getFileUuid().trim().isEmpty()) {
                    log.error("批量插入业务信息失败：文件UUID不能为空");
                    return false;
                }
                if (param.getBusinessType() == null) {
                    log.error("批量插入业务信息失败：业务类型不能为空");
                    return false;
                }
                if (param.getBusinessId() == null) {
                    log.error("批量插入业务信息失败：业务ID不能为空");
                    return false;
                }
            }

            // 调用Service层处理 - 现在改为插入操作
            return attachService.batchInsertBusinessInfo(picParams);

        } catch (Exception e) {
            log.error("批量插入业务信息失败", e);
            return false;
        }
    }

    @Override
    public AttachQrDTO generateQrCode(AttachQRParam attachQRParam) {
        return null;
    }
}
